﻿
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DB {
    public class SqlServerDB : DbContext {
        public static string ConnectionStrings { get; set; }


        public SqlServerDB() : base() {
        }

        public SqlServerDB(DbContextOptions<DbContext> options) : base(options) {

        }

        protected override void OnModelCreating(ModelBuilder builder) {
            base.OnModelCreating(builder);

            builder.Entity<UserToRole>().HasKey(u => new { u.UserId, u.RoleId });
            //builder.ApplyConfiguration(new UserMap());
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
            optionsBuilder.UseSqlServer(ConnectionStrings);
        }

        /// <summary>
        /// 用户
        /// </summary>
        public DbSet<Users> Users { get; set; }

        /// <summary>
        /// 提现信息
        /// </summary>
        public DbSet<CashInfo> Cashes { get; set; }

        /// <summary>
        /// 地址
        /// </summary>
        public DbSet<ShippingAddress> ShippingAddress { get; set; }

        /// <summary>
        /// 权限
        /// </summary>
        public DbSet<RoleInfo> Roles { get; set; }

        /// <summary>
        /// 提现记录
        /// </summary>
        public DbSet<CashLog> CashLogs { get; set; }

        /// <summary>
        /// 收入明细
        /// </summary>
        public DbSet<IncomeInfo> Incomes { get; set; }

        /// <summary>
        /// 公告
        /// </summary>
        public DbSet<Notice> Notices { get; set; }

        /// <summary>
        /// 订单
        /// </summary>
        public DbSet<OrderInfos> Orders { get; set; }

        /// <summary>
        /// 商品
        /// </summary>
        public DbSet<ProductInfo> Products { get; set; }

        /// <summary>
        /// 系统参数设置
        /// </summary>
        public DbSet<SystemSetting> Settings { get; set; }

        /// <summary>
        /// 快递信息
        /// </summary>
        public DbSet<ExpressInfo> Expresses { get; set; }

        /// <summary>
        /// 升级记录，用于记录能获取感恩分红那次奖励的升级记录
        /// </summary>
        public DbSet<LevelUpLog> LevelUpLogs { get; set; }

        /// <summary>
        /// 用户权限表
        /// </summary>
        public DbSet<UserToRole> UserToRole { get; set; }
    }
}
